package demo_0402.homework;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class T3 {
    public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();

        // 保存当前日期
        int currentDay = calendar.get(Calendar.DAY_OF_MONTH);

        // 打印星期标题（英文格式）
        System.out.println("Sun Mon Tue Wed Thu Fri Sat");

        // 设置为当月第一天
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);

        // 打印首行缩进
        for (int i = 1; i < dayOfWeek; i++) {
            System.out.print("    "); // 使用4个空格与英文标题对齐
        }

        int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        for (int day = 1; day <= daysInMonth; day++) {
            // 使用保存的当前日期来判断是否为今天
            String dayStr = (day == currentDay) ? day + "*" : String.valueOf(day);
            System.out.printf("%3s ", dayStr);

            if ((day + dayOfWeek - 1) % 7 == 0)
                System.out.println();
        }
        System.out.println(); // 添加最后的换行
    }
}
